# /bin/bash

VERSION=5.0.3
DOCKEROPS=""

HOME_DIR=$(cd $(dirname $0);cd ../;pwd)
IMAGES_DIR=${HOME_DIR}/images
cd ${IMAGES_DIR}/cm

install_dir=${IMAGES_DIR}/cm/opengauss-${VERSION}
install_cm_dir=${IMAGES_DIR}/cm/cm-${VERSION}
install_om_dir=${IMAGES_DIR}/cm/om-${VERSION}
mkdir -p {opengauss-${VERSION},cm-${VERSION},om-${VERSION}} 
#openGauss-5.0.3-openEuler-64bit-om.tar.gz
#openGauss-5.0.3-openEuler-64bit-cm.tar.gz
install_om_pkg_name=${IMAGES_DIR}/openGauss-${VERSION}-openEuler-64bit-om.tar.gz
install_cm_pkg_name=${IMAGES_DIR}/openGauss-${VERSION}-openEuler-64bit-cm.tar.gz
install_package_name=${IMAGES_DIR}/openGauss-Lite-${VERSION}-openEuler-aarch64.tar.gz

install_package_bin_name="openGauss-Lite-${VERSION}-openEuler-aarch64.bin"
function unpack_opengauss_pkg(){
  tar zxf ${install_package_name} -C ${install_dir}
  cd ${install_dir}
  tar zxf ${install_package_bin_name}
  rm ${install_package_bin_name} 
  install_package_bin_sha256=$(echo ${install_package_bin_name}| awk -F '.bin' '{print $1}').sha256
  rm ${install_package_bin_sha256} 
  ls -lth
  tar zxf upgrade_sql.tar.gz
  rm upgrade_sql.tar.gz upgrade_sql.sha256 
  cd -
}

tar zxf ${install_om_pkg_name} -C ${install_om_dir} 
tar zxf ${install_cm_pkg_name} -C ${install_cm_dir}
unpack_opengauss_pkg
# docker build  -t gauss-openeuler-os:22.03 -f Dockerfile_os .
docker build  -force-rm=true --no-cache=true \
       $DOCKEROPS \
       --build-arg="GAUSS_VERSION=${VERSION}" \
       -t opengauss-cm:5.0.3 -f Dockerfile .
# rm -rf ${install_dir}
# export GS_PASSWORD='Gauss!23'
# select name, setting from pg_settings where upper(name) like upper('%password%');
